package com.aloaproject.ciquta;

/**
 * Return true only if all contained {@link Criterion criterions} return true.
 * @author Daniele Demichelis
 */
public final class AndCriterion extends MultipleCriterion {

    /**
     * A new empty AndCriterion.
     * Clients should use the static methods provided
     * by {@link Criteria} to get an instance.
     */
    AndCriterion() {
        super();
    }

    /**
     * A new AndCriterion.
     * Clients should use the static methods provided
     * by {@link Criteria} to get an instance.
     * @param criterions    The list of {@link Criteerion criterions}
     *                      that will be evaluated in disjunction.
     */
    AndCriterion(final Criterion... criterions) {
        super(criterions);
    }

    /**
     * Match an object if all {@link Criterion criterions} match.
     * A shortand and style is used.
     */
    public boolean match(final Object object) {
        boolean match = true;
        for(int i=0; match == true && i < getCriterions().size(); i++){
            match = match && getCriterions().get(i).match(object);
        }
        return match;
    }

}
